package com.ruoyi.web.controller.module;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.module.domain.AreaInfo;
import com.ruoyi.module.service.IAreaInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 省市区地理位置Controller
 *
 * @author fubojin
 * @date 2024-12-06
 */
@RestController
@RequestMapping("/module/info")
public class AreaInfoController extends BaseController
{
    @Autowired
    private IAreaInfoService areaInfoService;

    /**
     * 查询省市区地理位置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(AreaInfo areaInfo)
    {
        startPage();
        List<AreaInfo> list = areaInfoService.selectAreaInfoList(areaInfo);
        return getDataTable(list);
    }

    /**
     * 导出省市区地理位置列表
     */
    @Log(title = "省市区地理位置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AreaInfo areaInfo)
    {
        List<AreaInfo> list = areaInfoService.selectAreaInfoList(areaInfo);
        ExcelUtil<AreaInfo> util = new ExcelUtil<AreaInfo>(AreaInfo.class);
        util.exportExcel(response, list, "省市区地理位置数据");
    }

    /**
     * 获取省市区地理位置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(areaInfoService.selectAreaInfoById(id));
    }

    /**
     * 新增省市区地理位置
     */
    @Log(title = "省市区地理位置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AreaInfo areaInfo)
    {
        return toAjax(areaInfoService.insertAreaInfo(areaInfo));
    }

    /**
     * 修改省市区地理位置
     */
    @Log(title = "省市区地理位置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AreaInfo areaInfo)
    {
        return toAjax(areaInfoService.updateAreaInfo(areaInfo));
    }

    /**
     * 删除省市区地理位置
     */
    @Log(title = "省市区地理位置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(areaInfoService.deleteAreaInfoByIds(ids));
    }
}
